package cloud.zhixinglu.www.spring.boot.paho.mqtt.controller;

import cloud.zhixinglu.www.spring.boot.paho.mqtt.enums.TopicEnum;
import cloud.zhixinglu.www.spring.boot.paho.mqtt.mqtt.MqttProviderConfig;
import cloud.zhixinglu.www.spring.boot.utils.date.FormatDateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * <p>
 * SampleController
 * </p>
 *
 * @author weixin
 * @date 2023/4/15 18:38
 */
@Slf4j
@RequestMapping("/test/")
@RestController
public class SampleController {


    private final MqttProviderConfig providerConfig;

    public SampleController(MqttProviderConfig providerConfig){
        this.providerConfig = providerConfig;
    }

    @GetMapping("sendDelayed")
    public void sendDelayedMessage(){

        Date date = new Date(System.currentTimeMillis());
        String dateString = FormatDateUtil.format(date);
        String topic = TopicEnum.DELAYED_BASE.getTopic() + "10" + TopicEnum.DELAYED_USER_LOGOUT_ISSUED.getTopic();
        String message = "test: " + dateString;
        providerConfig.publish(2, false, topic, message);
        log.info("SampleController.sendDelayedMessage info, delay topic: {}, message: {}", topic, message);
        FormatDateUtil.clearThreadLocal();
    }

}
